class MainWapper extends egret.DisplayObjectContainer {
    private container: egret.Sprite = new egret.Sprite()
    // private bg: egret.Bitmap = new egret.Bitmap()
    private bg = Utils.createBitmapByName('bg_1_png')
    private qr = Utils.createBitmapByName('front_qr_png')
    public constructor() {
        super()
        this.once(egret.Event.ADDED_TO_STAGE, this.init, this)
    }
    private init() {
        this.addChild(this.container)
        this.createBG()
        this.createQR()
        // this.createRO()
        this.createCL()
        this.setting()
    }
    private setting() {
        this.width = this.bg.width
        this.height = this.bg.height + this.qr.height
    }
    private createBG() {
        this.resetBG()
        this.container.addChild(this.bg)
    }
    private createQR() {
        this.container.addChild(this.qr)
        this.qr.y = this.bg.height
    }
    private createRO() {
        const role = Utils.createBitmapByName('girl_1_png')
        this.container.addChild(role)
        role.y = 50
    }
    private item_t
    private item_l
    private item_r
    public createCL() {
        const handler = () => {
            const num = Math.floor(Math.random() * 11 + 1)
            this.item_t = new CL_2(`${num}_t_png`)
            this.item_l = new CL_1(`${num}_l_png`)
            this.item_r = new CL_1(`${num}_r_png`)
            this.container.addChild(this.item_t)
            this.container.addChild(this.item_l)
            this.container.addChild(this.item_r)
        }

        try {
            this.container.removeChild(this.item_t)
            this.container.removeChild(this.item_l)
            this.container.removeChild(this.item_r)
            handler()
        } catch (error) {
            handler()
        }

        this.item_t.x = 135
        this.item_l.x = 420
        this.item_r.x = 10
        this.item_t.y = this.item_r.y = this.item_l.y = 18
        egret.Tween.removeTweens(this)
        egret.Tween.get(this).wait(3000).call(() => this.dispatchEvent(new egret.Event('setting_over')))
    }
    public resetBG() {
        ParamsPool.MergeFace().then(res => {
            egret.BitmapData.create('base64', ParamsPool.RES_PHOTO, bitmapData => {
                const texture = new egret.Texture()
                texture.bitmapData = bitmapData
                this.bg.texture = texture
                $('.loading-mask').hide()
                this.dispatchEvent(new egret.Event('setting_over'))
            })
        })
    }
}